import React, { PropTypes } from 'react';
import '../less/index.less'
import constants from '../../../../common/constants';
import request from '../../../../utils/request';
import { hashHistory} from 'react-router';

const userHeadBig = constants.userHeadBig;
const arrow = constants.arrow;
const propTypes = {
    userMsg: PropTypes.string.isRequired
};
class AccoutMsg extends React.Component {
    constructor(props) {
        super(props);
    }
    userDetail = (e) => {
        const isLogin = localStorage.getItem("isLogin");
        if (isLogin === '0'){
            hashHistory.push({
                pathname: '/login',
            })
        }else if (isLogin === '1'){
            hashHistory.push({
                pathname: '/user/details',
                state: this.props.userMsg
            })
        }

    }
    render() {
        return (
            <div className="accoutMsg radius">
                <div>
                    <div className="userHeadBig">
                        <img src={(this.props.userMsg.user_picture === undefined) || (this.props.userMsg.user_picture === '') ? userHeadBig : this.props.userMsg.user_picture}/>
                    </div>
                    <div className="userName">
                        <span onClick={this.userDetail.bind(this)}>{this.props.userMsg.user_name === '' ? '登录／注册' : this.props.userMsg.user_name}</span>
                    </div>
                    <div className="arrow">
                        <img src={arrow}/>
                    </div>
                </div>
            </div>
        );
    }
}

AccoutMsg.propTypes = propTypes;
export default AccoutMsg;